package javacommon.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateUtils {
    /**
     * 
     * Description: <br>
     * 获得某时间的毫秒数<br>
     * 
     * @param utcTimeString 时间字符串
     * @param format 字符串格式
     * @return
     * @throws ParseException 
     * @see
     */
	public static long getTimeFromUtc(String utcTimeString, SimpleDateFormat format) throws ParseException {
		Date date = format.parse(utcTimeString);
		java.util.Calendar cal = java.util.Calendar.getInstance();
		cal.setTime(date);
		// 2、取得时间偏移量：
		int zoneOffset = cal.get(java.util.Calendar.ZONE_OFFSET);

		// 3、取得夏令时差：
		int dstOffset = cal.get(java.util.Calendar.DST_OFFSET);
		cal.add(java.util.Calendar.MILLISECOND, (zoneOffset + dstOffset));
		return cal.getTimeInMillis();
	}

	public static void main(String[] args) throws ParseException {
		String dateFormatSrcPattern = "MMM dd yyyy HH:mm:ss";
		SimpleDateFormat dateFormat1 = new SimpleDateFormat(dateFormatSrcPattern, new Locale("ENGLISH"));
		Date date = new Date(getTimeFromUtc("Apr 20 2013 00:02:47", dateFormat1));
		System.out.println(DateFormat.getDateTimeInstance().format(date));
	}
}
